<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <p>Hello World</p>
</head>
<body>
<form id='formTable' action="" method="post">
    <input id = "user_name" value ="name" type="text"/></form>
    <input id = "query" type="button" value ="查询" onclick="query()"/></form>
</body>
</html>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type ="text/javascript" >
    function query()
    {//ajax方法
        $.ajax({
            type:"GET",//请求方式
            url:"/user/getUserById/1",//请求url
            dataType:"json",//返回数据类型
            success:function(data){
                $.each(data, function(key, val){
                    if(key=="name"){
                        document.getElementById("user_name").value = val;
                    }
                });
            },
            error:function(data){
                alert("error");
            }
        })
    }
</script>